home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / Caml Light 0.7 source / src / yacc / output.c < prev    next >
C/C++ Source or Header  |  1995-06-01  |  16KB  |  901 lines

  1. #include "defs.h"
  2.  
  3. static int nvectors;
  4. static int nentries;
  5. static short **froms;
  6. static short **tos;
  7. static short *tally;
  8. static short *width;
  9. static short *state_count;
  10. static short *order;
  11. static short *base;
  12. static short *pos;
  13. static int maxtable;
  14. static short *table;
  15. static short *check;
  16. static int lowzero;
  17. static int high;
  18.  
  19.  
  20. output()
  21. {
  22.   extern char *header[], *define_tables[];
  23.  
  24.   free_itemsets();
  25.   free_shifts();
  26.   free_reductions();
  27.   write_section(header);
  28.   output_stored_text();
  29.   output_transl();
  30.   output_rule_data();
  31.   output_yydefred();
  32.   output_actions();
  33.   free_parser();
  34.   output_debug();
  35.   output_trailing_text();
  36.   if (sflag)
  37.     fprintf(output_file,
  38.       "let yyact = make_vect %d (fun () -> (failwith \"parser\" : obj));;\n",
  39.       ntotalrules);
  40.   else
  41.     fprintf(output_file,
  42.       "let yyact = [|\n  (fun () -> failwith \"parser\")\n");
  43.   output_semantic_actions();
  44.   if (!sflag)
  45.     fprintf(output_file, "|];;\n");
  46.   write_section(define_tables);
  47.   output_entries();
  48. }
  49.  
  50.  
  51. static void output_char(n)
  52.      unsigned n;
  53. {
  54.   n = n & 0xFF;
  55.   putc('\\', output_file);
  56.   putc('0' + n / 100, output_file);
  57.   putc('0' + (n / 10) % 10, output_file);
  58.   putc('0' + n % 10, output_file);
  59. }
  60.  
  61. static void output_short(n)
  62.      int n;
  63. {
  64.   output_char(n);
  65.   output_char(n >> 8);
  66. }
  67.  
  68. output_rule_data()
  69. {
  70.     register int i;
  71.     register int j;
  72.  
  73.   
  74.     fprintf(output_file, "let yylhs = \"");
  75.     output_short(symbol_value[start_symbol]);
  76.  
  77.     j = 8;
  78.     for (i = 3; i < nrules; i++)
  79.     {
  80.     if (j >= 8)
  81.     {
  82.         if (!rflag) ++outline;
  83.         fprintf(output_file, "\\\n");
  84.         j = 1;
  85.     }
  86.         else
  87.         ++j;
  88.  
  89.         output_short(symbol_value[rlhs[i]]);
  90.     }
  91.     if (!rflag) outline += 2;
  92.     fprintf(output_file, "\";;\n\n");
  93.  
  94.     fprintf(output_file, "let yylen = \"");
  95.     output_short(2);
  96.  
  97.     j = 8;
  98.     for (i = 3; i < nrules; i++)
  99.     {
  100.     if (j >= 8)
  101.     {
  102.         if (!rflag) ++outline;
  103.         fprintf(output_file, "\\\n");
  104.         j = 1;
  105.     }
  106.     else
  107.       j++;
  108.  
  109.         output_short(rrhs[i + 1] - rrhs[i] - 1);
  110.     }
  111.     if (!rflag) outline += 2;
  112.     fprintf(output_file, "\";;\n\n");
  113. }
  114.  
  115.  
  116. output_yydefred()
  117. {
  118.     register int i, j;
  119.  
  120.     fprintf(output_file, "let yydefred = \"");
  121.     output_short(defred[0] ? defred[0] - 2 : 0);
  122.  
  123.     j = 8;
  124.     for (i = 1; i < nstates; i++)
  125.     {
  126.     if (j < 8)
  127.         ++j;
  128.     else
  129.     {
  130.         if (!rflag) ++outline;
  131.         fprintf(output_file, "\\\n");
  132.         j = 1;
  133.     }
  134.  
  135.     output_short(defred[i] ? defred[i] - 2 : 0);
  136.     }
  137.  
  138.     if (!rflag) outline += 2;
  139.     fprintf(output_file, "\";;\n\n");
  140. }
  141.  
  142.  
  143. output_actions()
  144. {
  145.     nvectors = 2*nstates + nvars;
  146.  
  147.     froms = NEW2(nvectors, short *);
  148.     tos = NEW2(nvectors, short *);
  149.     tally = NEW2(nvectors, short);
  150.     width = NEW2(nvectors, short);
  151.  
  152.     token_actions();
  153.     FREE(lookaheads);
  154.     FREE(LA);
  155.     FREE(LAruleno);
  156.     FREE(accessing_symbol);
  157.  
  158.     goto_actions();
  159.     FREE(goto_map + ntokens);
  160.     FREE(from_state);
  161.     FREE(to_state);
  162.  
  163.     sort_actions();
  164.     pack_table();
  165.     output_base();
  166.     output_table();
  167.     output_check();
  168. }
  169.  
  170.  
  171. token_actions()
  172. {
  173.     register int i, j;
  174.     register int shiftcount, reducecount;
  175.     register int max, min;
  176.     register short *actionrow, *r, *s;
  177.     register action *p;
  178.  
  179.     actionrow = NEW2(2*ntokens, short);
  180.     for (i = 0; i < nstates; ++i)
  181.     {
  182.     if (parser[i])
  183.     {
  184.         for (j = 0; j < 2*ntokens; ++j)
  185.         actionrow[j] = 0;
  186.  
  187.         shiftcount = 0;
  188.         reducecount = 0;
  189.         for (p = parser[i]; p; p = p->next)
  190.         {
  191.         if (p->suppressed == 0)
  192.         {
  193.             if (p->action_code == SHIFT)
  194.             {
  195.             ++shiftcount;
  196.             actionrow[p->symbol] = p->number;
  197.             }
  198.             else if (p->action_code == REDUCE && p->number != defred[i])
  199.             {
  200.             ++reducecount;
  201.             actionrow[p->symbol + ntokens] = p->number;
  202.             }
  203.         }
  204.         }
  205.  
  206.         tally[i] = shiftcount;
  207.         tally[nstates+i] = reducecount;
  208.         width[i] = 0;
  209.         width[nstates+i] = 0;
  210.         if (shiftcount > 0)
  211.         {
  212.         froms[i] = r = NEW2(shiftcount, short);
  213.         tos[i] = s = NEW2(shiftcount, short);
  214.         min = MAXSHORT;
  215.         max = 0;
  216.         for (j = 0; j < ntokens; ++j)
  217.         {
  218.             if (actionrow[j])
  219.             {
  220.             if (min > symbol_value[j])
  221.                 min = symbol_value[j];
  222.             if (max < symbol_value[j])
  223.                 max = symbol_value[j];
  224.             *r++ = symbol_value[j];
  225.             *s++ = actionrow[j];
  226.             }
  227.         }
  228.         width[i] = max - min + 1;
  229.         }
  230.         if (reducecount > 0)
  231.         {
  232.         froms[nstates+i] = r = NEW2(reducecount, short);
  233.         tos[nstates+i] = s = NEW2(reducecount, short);
  234.         min = MAXSHORT;
  235.         max = 0;
  236.         for (j = 0; j < ntokens; ++j)
  237.         {
  238.             if (actionrow[ntokens+j])
  239.             {
  240.             if (min > symbol_value[j])
  241.                 min = symbol_value[j];
  242.             if (max < symbol_value[j])
  243.                 max = symbol_value[j];
  244.             *r++ = symbol_value[j];
  245.             *s++ = actionrow[ntokens+j] - 2;
  246.             }
  247.         }
  248.         width[nstates+i] = max - min + 1;
  249.         }
  250.     }
  251.     }
  252.     FREE(actionrow);
  253. }
  254.  
  255. goto_actions()
  256. {
  257.     register int i, j, k;
  258.  
  259.     state_count = NEW2(nstates, short);
  260.  
  261.     k = default_goto(start_symbol + 1);
  262.     fprintf(output_file, "let yydgoto = \"");
  263.     output_short(k);
  264.  
  265.     save_column(start_symbol + 1, k);
  266.  
  267.     j = 8;
  268.     for (i = start_symbol + 2; i < nsyms; i++)
  269.     {
  270.     if (j >= 8)
  271.     {
  272.         if (!rflag) ++outline;
  273.         fprintf(output_file, "\\\n");
  274.         j = 1;
  275.     }
  276.     else
  277.         ++j;
  278.  
  279.     k = default_goto(i);
  280.     output_short(k);
  281.     save_column(i, k);
  282.     }
  283.  
  284.     if (!rflag) outline += 2;
  285.     fprintf(output_file, "\";;\n\n");
  286.     FREE(state_count);
  287. }
  288.  
  289. int
  290. default_goto(symbol)
  291. int symbol;
  292. {
  293.     register int i;
  294.     register int m;
  295.     register int n;
  296.     register int default_state;
  297.     register int max;
  298.  
  299.     m = goto_map[symbol];
  300.     n = goto_map[symbol + 1];
  301.  
  302.     if (m == n) return (0);
  303.  
  304.     for (i = 0; i < nstates; i++)
  305.     state_count[i] = 0;
  306.  
  307.     for (i = m; i < n; i++)
  308.     state_count[to_state[i]]++;
  309.  
  310.     max = 0;
  311.     default_state = 0;
  312.     for (i = 0; i < nstates; i++)
  313.     {
  314.     if (state_count[i] > max)
  315.     {
  316.         max = state_count[i];
  317.         default_state = i;
  318.     }
  319.     }
  320.  
  321.     return (default_state);
  322. }
  323.  
  324.  
  325.  
  326. save_column(symbol, default_state)
  327. int symbol;
  328. int default_state;
  329. {
  330.     register int i;
  331.     register int m;
  332.     register int n;
  333.     register short *sp;
  334.     register short *sp1;
  335.     register short *sp2;
  336.     register int count;
  337.     register int symno;
  338.  
  339.     m = goto_map[symbol];
  340.     n = goto_map[symbol + 1];
  341.  
  342.     count = 0;
  343.     for (i = m; i < n; i++)
  344.     {
  345.     if (to_state[i] != default_state)
  346.         ++count;
  347.     }
  348.     if (count == 0) return;
  349.  
  350.     symno = symbol_value[symbol] + 2*nstates;
  351.  
  352.     froms[symno] = sp1 = sp = NEW2(count, short);
  353.     tos[symno] = sp2 = NEW2(count, short);
  354.  
  355.     for (i = m; i < n; i++)
  356.     {
  357.     if (to_state[i] != default_state)
  358.     {
  359.         *sp1++ = from_state[i];
  360.         *sp2++ = to_state[i];
  361.     }
  362.     }
  363.  
  364.     tally[symno] = count;
  365.     width[symno] = sp1[-1] - sp[0] + 1;
  366. }
  367.  
  368. sort_actions()
  369. {
  370.   register int i;
  371.   register int j;
  372.   register int k;
  373.   register int t;
  374.   register int w;
  375.  
  376.   order = NEW2(nvectors, short);
  377.   nentries = 0;
  378.  
  379.   for (i = 0; i < nvectors; i++)
  380.     {
  381.       if (tally[i] > 0)
  382.     {
  383.       t = tally[i];
  384.       w = width[i];
  385.       j = nentries - 1;
  386.  
  387.       while (j >= 0 && (width[order[j]] < w))
  388.         j--;
  389.  
  390.       while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
  391.         j--;
  392.  
  393.       for (k = nentries - 1; k > j; k--)
  394.         order[k + 1] = order[k];
  395.  
  396.       order[j + 1] = i;
  397.       nentries++;
  398.     }
  399.     }
  400. }
  401.  
  402.  
  403. pack_table()
  404. {
  405.     register int i;
  406.     register int place;
  407.     register int state;
  408.  
  409.     base = NEW2(nvectors, short);
  410.     pos = NEW2(nentries, short);
  411.  
  412.     maxtable = 1000;
  413.     table = NEW2(maxtable, short);
  414.     check = NEW2(maxtable, short);
  415.  
  416.     lowzero = 0;
  417.     high = 0;
  418.  
  419.     for (i = 0; i < maxtable; i++)
  420.     check[i] = -1;
  421.  
  422.     for (i = 0; i < nentries; i++)
  423.     {
  424.     state = matching_vector(i);
  425.  
  426.     if (state < 0)
  427.         place = pack_vector(i);
  428.     else
  429.         place = base[state];
  430.  
  431.     pos[i] = place;
  432.     base[order[i]] = place;
  433.     }
  434.  
  435.     for (i = 0; i < nvectors; i++)
  436.     {
  437.     if (froms[i])
  438.         FREE(froms[i]);
  439.     if (tos[i])
  440.         FREE(tos[i]);
  441.     }
  442.  
  443.     FREE(froms);
  444.     FREE(tos);
  445.     FREE(pos);
  446. }
  447.  
  448.  
  449. /*  The function matching_vector determines if the vector specified by    */
  450. /*  the input parameter matches a previously considered    vector.  The    */
  451. /*  test at the start of the function checks if the vector represents    */
  452. /*  a row of shifts over terminal symbols or a row of reductions, or a    */
  453. /*  column of shifts over a nonterminal symbol.  Berkeley Yacc does not    */
  454. /*  check if a column of shifts over a nonterminal symbols matches a    */
  455. /*  previously considered vector.  Because of the nature of LR parsing    */
  456. /*  tables, no two columns can match.  Therefore, the only possible    */
  457. /*  match would be between a row and a column.  Such matches are    */
  458. /*  unlikely.  Therefore, to save time, no attempt is made to see if a    */
  459. /*  column matches a previously considered vector.            */
  460. /*                                    */
  461. /*  Matching_vector is poorly designed.  The test could easily be made    */
  462. /*  faster.  Also, it depends on the vectors being in a specific    */
  463. /*  order.                                */
  464.  
  465. int
  466. matching_vector(vector)
  467. int vector;
  468. {
  469.     register int i;
  470.     register int j;
  471.     register int k;
  472.     register int t;
  473.     register int w;
  474.     register int match;
  475.     register int prev;
  476.  
  477.     i = order[vector];
  478.     if (i >= 2*nstates)
  479.     return (-1);
  480.  
  481.     t = tally[i];
  482.     w = width[i];
  483.  
  484.     for (prev = vector - 1; prev >= 0; prev--)
  485.     {
  486.     j = order[prev];
  487.     if (width[j] != w || tally[j] != t)
  488.         return (-1);
  489.  
  490.     match = 1;
  491.     for (k = 0; match && k < t; k++)
  492.     {
  493.         if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
  494.         match = 0;
  495.     }
  496.  
  497.     if (match)
  498.         return (j);
  499.     }
  500.  
  501.     return (-1);
  502. }
  503.  
  504.  
  505.  
  506. int
  507. pack_vector(vector)
  508. int vector;
  509. {
  510.     register int i, j, k, l;
  511.     register int t;
  512.     register int loc;
  513.     register int ok;
  514.     register short *from;
  515.     register short *to;
  516.     int newmax;
  517.  
  518.     i = order[vector];
  519.     t = tally[i];
  520.     assert(t);
  521.  
  522.     from = froms[i];
  523.     to = tos[i];
  524.  
  525.     j = lowzero - from[0];
  526.     for (k = 1; k < t; ++k)
  527.     if (lowzero - from[k] > j)
  528.         j = lowzero - from[k];
  529.     for (;; ++j)
  530.     {
  531.     if (j == 0)
  532.         continue;
  533.     ok = 1;
  534.     for (k = 0; ok && k < t; k++)
  535.     {
  536.         loc = j + from[k];
  537.         if (loc >= maxtable)
  538.         {
  539.         if (loc >= MAXTABLE)
  540.             fatal("maximum table size exceeded");
  541.  
  542.         newmax = maxtable;
  543.         do { newmax += 200; } while (newmax <= loc);
  544.         table = (short *) REALLOC(table, newmax*sizeof(short));
  545.         if (table == 0) no_space();
  546.         check = (short *) REALLOC(check, newmax*sizeof(short));
  547.         if (check == 0) no_space();
  548.         for (l  = maxtable; l < newmax; ++l)
  549.         {
  550.             table[l] = 0;
  551.             check[l] = -1;
  552.         }
  553.         maxtable = newmax;
  554.         }
  555.  
  556.         if (check[loc] != -1)
  557.         ok = 0;
  558.     }
  559.     for (k = 0; ok && k < vector; k++)
  560.     {
  561.         if (pos[k] == j)
  562.         ok = 0;
  563.     }
  564.     if (ok)
  565.     {
  566.         for (k = 0; k < t; k++)
  567.         {
  568.         loc = j + from[k];
  569.         table[loc] = to[k];
  570.         check[loc] = from[k];
  571.         if (loc > high) high = loc;
  572.         }
  573.  
  574.         while (check[lowzero] != -1)
  575.         ++lowzero;
  576.  
  577.         return (j);
  578.     }
  579.     }
  580. }
  581.  
  582.  
  583.  
  584. output_base()
  585. {
  586.     register int i, j;
  587.  
  588.     fprintf(output_file, "let yysindex = \"");
  589.     output_short(base[0]);
  590.  
  591.     j = 8;
  592.     for (i = 1; i < nstates; i++)
  593.     {
  594.     if (j >= 8)
  595.     {
  596.         if (!rflag) ++outline;
  597.         fprintf(output_file, "\\\n");
  598.         j = 1;
  599.     }
  600.     else
  601.         ++j;
  602.  
  603.     output_short(base[i]);
  604.     }
  605.  
  606.     if (!rflag) outline += 2;
  607.     fprintf(output_file, "\";;\n\n");
  608.  
  609.     fprintf(output_file, "let yyrindex = \"");
  610.     output_short(base[nstates]);
  611.  
  612.     j = 8;
  613.     for (i = nstates + 1; i < 2*nstates; i++)
  614.     {
  615.     if (j >= 8)
  616.     {
  617.         if (!rflag) ++outline;
  618.         fprintf(output_file, "\\\n");
  619.         j = 1;
  620.     }
  621.     else
  622.         ++j;
  623.  
  624.     output_short(base[i]);
  625.     }
  626.  
  627.     if (!rflag) outline += 2;
  628.     fprintf(output_file, "\";;\n\n");
  629.  
  630.     fprintf(output_file, "let yygindex = \"");
  631.     output_short(base[2*nstates]);
  632.  
  633.     j = 8;
  634.     for (i = 2*nstates + 1; i < nvectors - 1; i++)
  635.     {
  636.     if (j >= 8)
  637.     {
  638.         if (!rflag) ++outline;
  639.         fprintf(output_file, "\\\n");
  640.         j = 1;
  641.     }
  642.     else
  643.         ++j;
  644.  
  645.     output_short(base[i]);
  646.     }
  647.  
  648.     if (!rflag) outline += 2;
  649.     fprintf(output_file, "\";;\n\n");
  650.     FREE(base);
  651. }
  652.  
  653.  
  654.  
  655. output_table()
  656. {
  657.     register int i;
  658.     register int j;
  659.  
  660.     ++outline;
  661.     fprintf(code_file, "let YYTABLESIZE = %d;;\n", high);
  662.     fprintf(output_file, "let yytable = \"");
  663.     output_short(table[0]);
  664.  
  665.     j = 8;
  666.     for (i = 1; i <= high; i++)
  667.     {
  668.     if (j >= 8)
  669.     {
  670.         if (!rflag) ++outline;
  671.         fprintf(output_file, "\\\n");
  672.         j = 1;
  673.     }
  674.     else
  675.         ++j;
  676.  
  677.     output_short(table[i]);
  678.     }
  679.  
  680.     if (!rflag) outline += 2;
  681.     fprintf(output_file, "\";;\n\n");
  682.     FREE(table);
  683. }
  684.  
  685.  
  686.  
  687. output_check()
  688. {
  689.     register int i;
  690.     register int j;
  691.  
  692.     fprintf(output_file, "let yycheck = \"");
  693.     output_short(check[0]);
  694.  
  695.     j = 8;
  696.     for (i = 1; i <= high; i++)
  697.     {
  698.     if (j >= 8)
  699.     {
  700.         if (!rflag) ++outline;
  701.         fprintf(output_file, "\\\n");
  702.         j = 1;
  703.     }
  704.     else
  705.         ++j;
  706.  
  707.     output_short(check[i]);
  708.     }
  709.  
  710.     if (!rflag) outline += 2;
  711.     fprintf(output_file, "\";;\n\n");
  712.     FREE(check);
  713. }
  714.  
  715.  
  716. output_transl()
  717. {
  718.   int i;
  719.  
  720.   fprintf(code_file, "let yytransl = [|\n");
  721.   for (i = 0; i < ntokens; i++) {
  722.     if (symbol_true_token[i]) {
  723.       fprintf(code_file, "  %3d (* %s *);\n", symbol_value[i], symbol_name[i]);
  724.     }
  725.   }
  726.   fprintf(code_file, "    0|];;\n\n");
  727. }
  728.  
  729. output_stored_text()
  730. {
  731.     register int c;
  732.     register FILE *in, *out;
  733.  
  734.     fclose(text_file);
  735.     text_file = fopen(text_file_name, "r");
  736.     if (text_file == NULL)
  737.     open_error(text_file_name);
  738.     in = text_file;
  739.     if ((c = getc(in)) == EOF)
  740.     return;
  741.     out = code_file;
  742.     if (c ==  '\n')
  743.     ++outline;
  744.     putc(c, out);
  745.     while ((c = getc(in)) != EOF)
  746.     {
  747.     if (c == '\n')
  748.         ++outline;
  749.     putc(c, out);
  750.     }
  751.     if (!lflag)
  752.     fprintf(out, line_format, ++outline + 1, code_file_name);
  753. }
  754.  
  755.  
  756. output_debug()
  757. {
  758. }
  759.  
  760. output_trailing_text()
  761. {
  762.     register int c, last;
  763.     register FILE *in, *out;
  764.  
  765.     if (line == 0)
  766.     return;
  767.  
  768.     in = input_file;
  769.     out = code_file;
  770.     c = *cptr;
  771.     if (c == '\n')
  772.     {
  773.     ++lineno;
  774.     if ((c = getc(in)) == EOF)
  775.         return;
  776.     if (!lflag)
  777.     {
  778.         ++outline;
  779.         fprintf(out, line_format, lineno, input_file_name);
  780.     }
  781.     if (c == '\n')
  782.         ++outline;
  783.     putc(c, out);
  784.     last = c;
  785.     }
  786.     else
  787.     {
  788.     if (!lflag)
  789.     {
  790.         ++outline;
  791.         fprintf(out, line_format, lineno, input_file_name);
  792.     }
  793.     do { putc(c, out); } while ((c = *++cptr) != '\n');
  794.     ++outline;
  795.     putc('\n', out);
  796.     last = '\n';
  797.     }
  798.  
  799.     while ((c = getc(in)) != EOF)
  800.     {
  801.     if (c == '\n')
  802.         ++outline;
  803.     putc(c, out);
  804.     last = c;
  805.     }
  806.  
  807.     if (last != '\n')
  808.     {
  809.     ++outline;
  810.     putc('\n', out);
  811.     }
  812.     if (!lflag)
  813.     fprintf(out, line_format, ++outline + 1, code_file_name);
  814. }
  815.  
  816.  
  817. copy_file(file, file_name)
  818.      FILE ** file;
  819.      char * file_name;
  820. {
  821.   register int c, last;
  822.   register FILE *out;
  823.  
  824.   fclose(*file);
  825.     *file = fopen(file_name, "r");
  826.     if (*file == NULL)
  827.     open_error(file_name);
  828.  
  829.     if ((c = getc(*file)) == EOF)
  830.     return;
  831.  
  832.     out = code_file;
  833.     last = c;
  834.     if (c == '\n')
  835.     ++outline;
  836.     putc(c, out);
  837.     while ((c = getc(*file)) != EOF)
  838.     {
  839.     if (c == '\n')
  840.         ++outline;
  841.     putc(c, out);
  842.     last = c;
  843.     }
  844.  
  845.     if (last != '\n')
  846.     {
  847.     ++outline;
  848.     putc('\n', out);
  849.     }
  850.  
  851. }
  852.  
  853. output_semantic_actions()
  854. {
  855.   copy_file (&action_file, action_file_name);
  856. }
  857.  
  858. output_entries()
  859. {
  860.   copy_file (&entry_file, entry_file_name);
  861. }
  862.  
  863. free_itemsets()
  864. {
  865.     register core *cp, *next;
  866.  
  867.     FREE(state_table);
  868.     for (cp = first_state; cp; cp = next)
  869.     {
  870.     next = cp->next;
  871.     FREE(cp);
  872.     }
  873. }
  874.  
  875.  
  876. free_shifts()
  877. {
  878.     register shifts *sp, *next;
  879.  
  880.     FREE(shift_table);
  881.     for (sp = first_shift; sp; sp = next)
  882.     {
  883.     next = sp->next;
  884.     FREE(sp);
  885.     }
  886. }
  887.  
  888.  
  889.  
  890. free_reductions()
  891. {
  892.     register reductions *rp, *next;
  893.  
  894.     FREE(reduction_table);
  895.     for (rp = first_reduction; rp; rp = next)
  896.     {
  897.     next = rp->next;
  898.     FREE(rp);
  899.     }
  900. }
  901.